package com.goods.Controller;

import com.common.entity.Result;
import com.github.pagehelper.PageInfo;
import com.goods.Service.GoodsService;
import com.goods.Pojo.Goods;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/goods")
@RefreshScope
public class GoodsController {
    @Autowired
    private GoodsService goodsService;
    //添加
    @PostMapping("/AddGoods")
    public Result AddGoods(@RequestBody Goods goods){
        goodsService.AddGoods(goods);
        return  Result.success();
    }
    //修改
    @PutMapping("/UpdateGoods")
    public Result UpdateGoods(@RequestBody Goods goods){
        goodsService.UpdateGoods(goods);
        return  Result.success();
    }
    //查询
    @GetMapping("/SearchGoods")
    public Result<PageInfo<Goods>> SearchGoods(@RequestParam Integer pageNum,
                              @RequestParam Integer pageSize,
                              @RequestParam String goodsName,
                              @RequestParam String factory){
        PageInfo<Goods> goodsPageInfo=goodsService.SearchGoods(pageNum,pageSize,goodsName,factory);
        return Result.success(goodsPageInfo);
    }
    //删除
    @DeleteMapping("/DelGoods")

    public Result DelGoods(@RequestParam Integer Id){
        goodsService.DelGoods(Id);
        return  Result.success();
    }

    //id查询商品信息
    @GetMapping("/getByid")
    public Result getByid(@RequestParam Integer Id){
        Goods goods=goodsService.getByid(Id);
        return Result.success(goods);
    }
    //查询列表
    @GetMapping("list")
    public Result searchlist(){
        List<Goods> list=goodsService.searchlist();
        return Result.success(list);
    }




}
